解决用gcc7.3链接gtest1.7的问题

您所在的位置:网站首页 gtest main 解决用gcc7.3链接gtest1.7的问题

解决用gcc7.3链接gtest1.7的问题

#解决用gcc7.3链接gtest1.7的问题| 来源: 网络整理| 查看: 265

最近要在新系统中使用gcc7.3, 配套使用的gtest是1.7版本的,对于下面的程序:

#include TEST(testSuite, ShouldSucceed) { EXPECT_EQ(1, 1); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv);

采用下面的命令

~/gcc/7.3.0_1/bin/g++ -std=c++11 -o g gtest_main_unittest.cc -I/gtest/1.7.0_1/include/ -L/gtest/1.7.0_1/lib/ -lgtest -lpthread

结果却发现怎么编译都不通过,一直报下面的错误:

/tmp/ccZdMeII.o: In function `testing::AssertionResult testing::internal::CmpHelperEQ(char const*, char const*, int const&, int const&)': gtest_main_unittest.cc:(.text._ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_[_ZN7testing8internal11CmpHelperEQIiiEENS_15AssertionResultEPKcS4_RKT_RKT0_]+0x8d): undefined reference to `testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string const&, std::__cxx11::basic_string const&, bool)' collect2: error: ld returned 1 exit status

最后请教了同事,才找到原因,原来我们编译gtest使用用的gcc版本是4.8.4,现在如果要在gcc7.3中使用的话,必须要保持ABI兼容,上面的命令最后加上 -D_GLIBCXX_USE_CXX11_ABI=0:

~/gcc/7.3.0_1/bin/g++ -std=c++11 -o g gtest_main_unittest.cc -I/gtest/1.7.0_1/include/ -L/gtest/1.7.0_1/lib/ -lgtest -lpthread -D_GLIBCXX_USE_CXX11_ABI=0

对于CMake文件,加上下面一句也可以了

add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3